home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1986, 1988 Regents of the University of California
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /* set.h -- definitions for sets */
-
- #ifndef set_h
- #define set_h
-
- #include "attribute.h"
-
- #define MAXNODES 2000 /* maximum number of nodes */
- #define BITS_PER_CHAR 8 /* number of bits in a char */
- #define MAXBYTES (1 + (MAXNODES / BITS_PER_CHAR))
-
- struct set
- {
- int first, last;
- char bytes[MAXBYTES];
- };
-
- typedef struct set SET;
-
- #ifndef MAX
- #define MAX(A,B) ( (A) > (B) ? (A) : (B) )
- #endif
-
- #ifndef MIN
- #define MIN(A,B) ( (A) < (B) ? (A) : (B) )
- #endif
-
- #define byte(n) (n >> 3) /* byte for element n */
- #define bit(n) (n & 07) /* bit in byte for element n */
-
- #define in(set, n) (((set)->bytes[byte(n)] >> bit(n)) & 01)
-
- #define adjust_set_limits(set) \
- { int i;\
- for (i = (set)->first; i < (set)->last + 1; i++)\
- {\
- (set)->first = i;\
- if (in(set,i))\
- break;\
- }\
- for (i = (set)->last; i > (set)->first - 1; i--)\
- {\
- (set)->last = i;\
- if (in(set,i))\
- break;\
- }\
- if (!in(set, (set)->first))\
- { (set)->first = MAXNODES - 1;\
- (set)->last = 0;\
- }\
- }
-
- #define add_element(set, n) \
- {\
- (set)->bytes[byte(n)] |= (1 << bit(n));\
- (set)->first = MIN((set)->first, n);\
- (set)->last = MAX((set)->last, n);\
- }
-
- #define remove_element(set, n) \
- {\
- (set)->bytes[byte(n)] &= ~(1 << bit(n));\
- if (n == (set)->first || n ==(set)->last) \
- adjust_set_limits(set);\
- }
- #define clear_set(set) \
- { int i;\
- for (i = 0; i < MAXBYTES; i++)\
- (set)->bytes[i] = 0;\
- (set)->first = MAXNODES - 1;\
- (set)->last = 0;\
- }
-
- #define init_set(set) { new(set, SET); clear_set(set); }
-
- #define copy_set(set2, set1) \
- { int i;\
- for (i = 0; i < MAXBYTES; i++)\
- (set2)->bytes[i] = (set1)->bytes[i];\
- (set2)->first = (set1)->first;\
- (set2)->last = (set1)->last;\
- }
-
- #define each_element(set, vno) \
- { for (vno = (set)->first; vno < (set)->last + 1; vno++)\
- if (in(set, vno))\
- {
-
- #define union(set1, set2) \
- { int i;\
- (set1)->first = MIN((set1)->first,(set2)->first);\
- (set1)->last = MAX((set1)->last,(set2)->last);\
- for (i = 0; i < MAXBYTES; i++)\
- (set1)->bytes[i] |= (set2)->bytes[i];\
- }
-
- #define intersect(set1, set2) \
- {\
- (set1)->first = MAX((set1)->first,(set2)->first);\
- (set1)->last = MIN((set1)->last,(set2)->last);\
- { int i;\
- for (i = 0; i < MAXBYTES; i++)\
- (set1)->bytes[i] &= (set2)->bytes[i];\
- adjust_set_limits(set1);\
- }\
- }
-
- #define difference(set1, set2) \
- { int i;\
- for (i = 0; i < MAXBYTES; i++)\
- (set1)->bytes[i] &= ~((set2)->bytes[i]);\
- adjust_set_limits(set1);\
- }
-
- #define xor(set1, set2) \
- {\
- (set1)->first = MIN((set1)->first,(set2)->first);\
- (set1)->last = MAX((set1)->last,(set2)->last);\
- { int i;\
- for (i = 0; i < MAXBYTES; i++)\
- (set1)->bytes[i] = ((set1)->bytes[i] | (set2)->bytes[i]) &\
- ~((set1)->bytes[i] & (set2)->bytes[i]);\
- adjust_set_limits(set1);\
- }\
- }
-
- BOOL empty();
- BOOL equal();
-
- #endif
-